package com.sakuracard.stepdemo.web.model;

public record ResponseResult<T>(int code, String msg, String status, T data) {
  private final static String SUCCESS_MSG = "操作成功";
  private final static String FAIL_MSG = "操作失败";
  private final static String STATUS_MSG_SUCCESS = "success";
  private final static String STATUS_MSG_FAIL = "error";
  private final static Object EMPTY_DATA = new Object();

  public static <T> ResponseResult<T> success(T data) {
    return success(data, SUCCESS_MSG);
  }

  public static ResponseResult<Object> fail() {
    return fail(FAIL_MSG);
  }

  public static ResponseResult<Object> fail(String msg) {
    return new ResponseResult<>(400, msg, STATUS_MSG_FAIL, EMPTY_DATA);
  }

  public static <T> ResponseResult<T> success(T data, String msg) {
    return new ResponseResult<T>(200, msg, STATUS_MSG_SUCCESS, data);
  }
}
